package com.foodplus.www.presenter;

import com.foodplus.www.api.BaseSubscriber;
import com.foodplus.www.api.ExceptionHandle;
import com.foodplus.www.bean.basket.AddGoodBean;
import com.foodplus.www.bean.good.siplegood.SipleGoodBean;
import com.foodplus.www.model.impl.BasketModelImpl;
import com.foodplus.www.model.impl.GoodModelImpl;
import com.foodplus.www.view.impl.SipleGoodView;

import java.util.Map;

/**
 * Created by WangZhiChao on 2016/10/31.
 */

public class SipleGoodPresenter {

    SipleGoodView view;

    public SipleGoodPresenter(SipleGoodView view) {
        this.view = view;
    }

    public void getSipGoodsData(Map<String, String> params) {
        new GoodModelImpl().getSipleGoodData(new BaseSubscriber<SipleGoodBean>() {
            @Override
            public void onSuccess(SipleGoodBean SigleGoodBean) {
                view.onSuccess(SigleGoodBean);
            }

            @Override
            public void onFail(ExceptionHandle.ResponeThrowable e) {
                view.onFail(e);
            }

            @Override
            public void onFinished() {
                view.onFinish();
            }
        }, params);
    }

    public void addToBasket(Map<String, String> params){
        new BasketModelImpl().addToBasket(params, new BaseSubscriber<AddGoodBean>() {
            @Override
            public void onSuccess(AddGoodBean addGoodBean) {
                view.onReceiveAddData(addGoodBean);
            }

            @Override
            public void onFail(ExceptionHandle.ResponeThrowable e) {
                view.onFail(e);
            }

            @Override
            public void onFinished() {
                view.onFinish();
            }
        });
    }
}
